package com.xuecheng.content.api;

import com.xuecheng.content.model.dto.BindTeachplanMediaDto;
import com.xuecheng.content.model.dto.SaveTeachplanDto;
import com.xuecheng.content.model.dto.TeachplanDto;
import com.xuecheng.content.service.TeachplanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(value = "课程计划编辑接口", tags = "课程计划编辑接口")
@Slf4j
public class TeachPlanController {

    @Autowired
    private TeachplanService teachplanService;

    @ApiOperation("查询课程计划树型结构")
    @ApiImplicitParam(value = "courseId", name = "课程Id", required = true, dataType = "Long", paramType = "path")
    @GetMapping("/teachplan/{courseId}/tree-nodes")
    public List<TeachplanDto> getTreeNodes(@PathVariable Long courseId) {
        log.info("根据课程id查询计划树型结构");
        return teachplanService.findTeachPlanTree(courseId);

    }

    @ApiOperation("课程计划修改或者创建")
    @PostMapping("/teachplan")
    public void saveTeachPlan(@RequestBody SaveTeachplanDto saveTeachplanDto) {
        log.info("课程计划修改或者创建");
        teachplanService.saveTeachplan(saveTeachplanDto);
    }


    @ApiOperation("根据课程计划id删除课程计划")
    @DeleteMapping("/teachplan/{teachplanId}")
    public void deleteTeachPlan(@PathVariable Long teachplanId) {
        teachplanService.deleteTeachplan(teachplanId);
    }

    @ApiOperation("课程排序")
    @ApiImplicitParams({@ApiImplicitParam(value = "teachplanId", name = "课程计划id", required = true, dataType = "String", paramType = "Long"),
            @ApiImplicitParam()})
    @PostMapping("/teachplan/{move}/{teachplanId}")
    public void moveOrDown(@PathVariable("move") String move, @PathVariable("teachplanId") Long teachplanId) {
        teachplanService.moveOrDown(move, teachplanId);
    }

    @ApiOperation(value = "课程计划和媒资信息绑定")
    @PostMapping("/teachplan/association/media")
    public void associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto){
            teachplanService.associationMedia(bindTeachplanMediaDto);
    }

    @ApiOperation(value = "删除绑定的媒资相关信息")
    @DeleteMapping("/teachplan/association/media/{teachPlanId}/{mediaId}")
    public void deleteAssociationMedia(@PathVariable("teachPlanId") Long teachPlanId,@PathVariable("mediaId") String mediaId){
            teachplanService.deleteAssociationMedia(teachPlanId,mediaId);
    }
}
